#include "Stdafx.h"
#include "MeanShiftTracker.h"

void cvLib::MeanShiftTracker::handleMouseEvents(int event, int x, int y, int flags, void *param){
	switch(event){
	case CV_EVENT_MOUSEMOVE:
		//std::cout << " mouse is moving..";
		if(onProcess){
			tmpSelection.width = x - tmpSelection.x;
			tmpSelection.height = y - tmpSelection.y;
		}
		break;
	case CV_EVENT_LBUTTONDOWN:
		tmpSelection = cvRect(x,y,0,0);
		onProcess = true;
		break;
	case CV_EVENT_LBUTTONUP:
		if(onProcess){
			if(tmpSelection.width > 0 && tmpSelection.height > 0){
				// draw the rectangle..
				drawRect = true;
				onProcess = false;
				tractObject = true;
				rectCount++;
				std::cout << "Number of objects selected.." << rectCount << std::endl;
			}
		}
		break;
	} // end of switch
}
void cvLib::MeanShiftTracker::drawRectangles(){
	CvPoint p1,p2;
	p1.x = tmpSelection.x;
	p2.x = tmpSelection.x + tmpSelection.width;
	p1.y = tmpSelection.y;
	p2.y = tmpSelection.y + tmpSelection.height;
	cvRectangle(frame,p1,p2,CV_RGB(255,0,0),1,CV_AA,0);
}
void cvLib::MeanShiftTracker::displayFrames(){
	cvShowImage("Tracking",frame);
}
void cvLib::MeanShiftTracker::setProperties(){
	fHeight = cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT);
	fWidth = cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH);
	frame = cvCreateImage(cvSize(fWidth,fHeight),IPL_DEPTH_8U,3);
}



